package reflectObject;

import java.util.Scanner;
import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.NotFoundException;
import javassist.Translator;
import javassist.tools.reflect.Loader;

/**
 * Chargement pour rendre reflective une application
 * @author 3003064 & 3153319
 *
 */
public class MyReflectMain {

	public static void main(String[] args) throws Throwable{
		ClassPool pool = ClassPool.getDefault();
		pool.importPackage("stores");
		pool.importPackage("junit");
		
		while(true)
		{
			try {
				Scanner sc = new Scanner(System.in);
				System.out.println("Entez le chemin du main que vous souhaitez tester Exemple : \test.array.Main or test.junit.Main\":  - ");
				String file = sc.next();	
				Translator t = new MakePublicTranslator();
				Loader cl  = new Loader();  //chargeur Javassist
				try {
					cl.addTranslator(pool, t);
					cl.run(file, args);
				} catch (NotFoundException e) {
					e.printStackTrace();
				} catch (CannotCompileException e) {
					e.printStackTrace();
				} catch (Throwable e) {
					e.printStackTrace();
				}
				sc.close();
			} catch (Throwable e) {
				System.out.println("Main don't exist");
			}
		}
	}
}
